import { AbsSvgUnitParser } from "../absunitparser"
import circle from "../../../../../canvas/common/struct/basestruct/circle";
import globalconst from "../../../../../canvas/common/globalConst";
var global = globalconst.GlobalConst;

class CircleParser extends AbsSvgUnitParser{
    constructor(){
        super();
        this.type = global.BaseUnitCircle<<16;
    }
    parse(mainEle){
        let unitInfo = new circle.Circle();
        unitInfo.type = this.type;

        const attributes = mainEle.attributes;
        for (let i = 0; i < attributes.length; i++) {
            const attr = attributes[i];
            if (attr.name == 'cx') {
                unitInfo.x = parseFloat(attr.value);
            }
            else if (attr.name == 'cy') {
                unitInfo.y = parseFloat(attr.value);
            }
            else if (attr.name == 'r') {
                unitInfo.radius = parseFloat(attr.value);
            }
        }
        this.parseCommonProp(unitInfo,mainEle);
        this.chg2SysCoord(unitInfo);
        unitInfo.pos.x = unitInfo.x;
        unitInfo.pos.y = unitInfo.y;
        unitInfo.pos.radius = unitInfo.radius;
        return unitInfo;
    }
}

export {CircleParser}